<?php

namespace App\Http\Controllers\Frontend\V10\BankCard;

use App\Models\RecommendCreditCard;
use App\Models\HotBank;
use App\Models\ProgressBank;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;


class RecommendCreditCardController extends Controller
{
    public function index()
    {
        $data = array();

        //办卡进度
        $url = ProgressBank::select('url')->where('status', 1)->first();
        $data['progress_url'] = $url ? $url->url : '';

        //热门银行
        $list = HotBank::select('card_img_url','credit_card_name','url')->where('status', 1)->get();
        if ($list) {
            $list = $list->toArray();
            $data['hot_banks'] = array_map(function ($v) {
                $v['card_img_url'] = getOssUrl($v['card_img_url']);
                return $v;
            }, $list);
        } else {
            $data['hot_banks'] = array();
        }

        //推荐信用卡
        $list = RecommendCreditCard::select(['card_img', 'title', 'subtitle', 'key_word', 'url'])->where('status', 1)
            ->orderByDesc('id')
            ->get();
        if ($list) {
            $list = $list->toArray();
            $data['recommend_cards'] = array_map(function ($v) {
                $v['card_img'] = getOssUrl($v['card_img']);
                return $v;
            }, $list);
        } else {
            $data['recommend_cards'] = array();
        }

        return success($data);
    }

}
